package com.cb.eduservice.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cb.eduservice.entity.EduCourse;
import com.cb.eduservice.entity.EduTeacher;
import com.cb.eduservice.service.EduCourseService;
import com.cb.eduservice.service.EduTeacherService;
import com.cb.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 前台讲师页管理
 *
 * @author cb
 * @version 1.0
 * @date 2020/6/28 14:40
 */
@Api(description = "前台讲师管理")

@RestController
@RequestMapping("/eduservice/teacherfront")
public class TeacherFrontController {

    private final EduTeacherService teacherService;

    private final EduCourseService courseService;

    @Autowired
    public TeacherFrontController(EduTeacherService teacherService, EduCourseService courseService) {
        this.teacherService = teacherService;
        this.courseService = courseService;
    }

    @ApiOperation("分页查询讲师")
    @PostMapping("getTeacherFrontList/{current}/{limit}")
    public R pageTeacher(@PathVariable("current")long current,
                         @PathVariable("limit")long limit){
        Page<EduTeacher> page = new Page<>(current, limit);
        Map<String,Object> map = teacherService.getTeacherFrontList(page);

        return R.ok().data(map);
    }

    @ApiOperation("根据讲师id查询讲师信息, 和关联课程信息")
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public R getTeacherInfo(@PathVariable("teacherId") String teacherId){
        // 查询讲师信息
        EduTeacher info = teacherService.getById(teacherId);

        // 查询课程信息
        List<EduCourse> list = courseService.getCourseByTeacherId(teacherId);

        return R.ok().data("teacher", info).data("courseList", list);
    }

}
